The Apple Event interface is relatively simple. This code registers a handler with the Apple Event Manager (specifically, to handle file creation notification):
AEEventHandlerUPP gCreateHandler = NewAEEventHandlerProc( XHandleCreate ); if ( theMask & kCreatedFile ) ::AEInstallEventHandler( kFileWatcherSuite, kCreatedFileID, gCreateHandler, 0, false );
The handler has the standard Apple Event handler signature:
pascal OSErr XHandleCreate( AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon );
It's a little trickier to register with the FBA:
// Address event using signature. theError = AECreateDesc( typeApplSignature, ( const void * )kFileWatcherSignature, sizeof( OSType ), &theAddressDesc ); // New event. theError = AECreateAppleEvent( kAECoreSuite, kAECreateElement, &theAddressDesc, kAutoGenerateReturnID, kAnyTransactionID, &theAppleEvent ); // Add type param. theError = AEPutParamPtr( &theAppleEvent, keyAEObjectClass, typeType, ( const void * )cFolderWatcher, sizeof( typeType ) ); // Create properties. theError = AECreateList( 0, 0, true, &theProperties ); // Add properties to event. theError = AEPutParamPtr( &theAppleEvent, keyAEPropData, typeAERecord, &theProperties, sizeof( typeAERecord ) ); // Populate properties: volume to watch. theError = AEPutKeyPtr( &theProperties, pFileWatcherAlias, typeAlias, "Cartman:", sizeof( typeAlias ) ); // Populate properties: go deep. theError = AEPutKeyPtr( &theProperties, pFileWatcherDeep, cBoolean, ( const void * )true, sizeof( cBoolean ) ); // Create activities descriptor list. theError = AECreateList( 0, 0, false, &theDescList ); // Populate activities descriptor list. if ( theMask & kCreatedFile ) theError = AEPutPtr( &theDescList, 0, pFileWatcherActivities, ( const void * )kFileCreatedActivity, sizeof( pFileWatcherActivities ) ); if ( theMask & kCreatedFolder ) theError = AEPutPtr( &theDescList, 0, pFileWatcherActivities, ( const void * )kFolderCreatedActivity, sizeof( pFileWatcherActivities ) ); if ( theMask & kRenamedItemID ) theError = AEPutPtr( &theDescList, 0, pFileWatcherActivities, ( const void * )kItemRenamedActivity, sizeof( pFileWatcherActivities ) ); if ( theMask & kDeletedItemID ) theError = AEPutPtr( &theDescList, 0, pFileWatcherActivities, ( const void * )kItemDeletedActivity, sizeof( pFileWatcherActivities ) ); if ( theMask & kMovedItemID ) theError = AEPutPtr( &theDescList, 0, pFileWatcherActivities, ( const void * )kItemMovedActivity, sizeof( pFileWatcherActivities ) ); // Populate properties: activities descriptor. theError = AEPutKeyDesc( &theProperties, pFileWatcherActivities, &theDescList ); // Send it. theError = AESend( &theAppleEvent, &theReply, kAEWaitReply, kAENormalPriority, kNoTimeOut, nil, nil ); // Cleanup. theError = AEDisposeDesc( &theDescList );
The demo app contains code that logs messages and creates aliases in response to input received from the FBA.